package com.qingxin.sys.verifier;

/**
 * 验证消息
 * @author JiWangli
 */
public class VerifyMsg {
	
	private String id;
	private String name;
	private String label;
	private String message;
	private String type;
	
	
	public VerifyMsg() {
	}
	
	
	public VerifyMsg(String id, String name, String label, String type, String message) {
		this.id = id;
		this.name = name;
		this.label = label;
		this.type = type;
		this.message = message;
	}


	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
	/**
	 * 获取带字段描述的验证信息
	 * 
	 * @param alwaysAddLabel 如果为true则直接在message前添加label信息，否则仅当message中不包含label时才添加
	 * @return
	 */
	public String getLabelMessage(boolean alwaysAddLabel) {
		if(label==null || label.length() == 0 || message == null){
			return message;
		}
		if(alwaysAddLabel){
			return label + "" + message;
		}
		if(message.indexOf(label) == -1){
			return label + "" + message;
		}
		return message;
	}
	
	
	
	@Override
	public String toString() {
		StringBuilder buf = new StringBuilder();
		if(label != null && message.indexOf(label) == -1){
			buf.append(label);
		}
		if(name != null && message.indexOf(name) == -1){
			buf.append("[").append(name).append("]");
		}
		buf.append(buf.length()>0?":":"").append(message);
		return buf.toString();
	}
	
	
	
}
